﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Text;
using System.Threading.Tasks;

namespace Molia.AppCenter.ViewModal
{
    public class MainViewModal : Service.IMessageAcceptable, INotifyPropertyChanged
    {
        public MainViewModal()
        {
            Service.MessageService.Registry(typeof(Component.Package), this, "PackageALL");
            Market.SetCache("G:\\项目\\Molia\\Molia.AppCenter\\Molia.AppCenter\\Designed\\Package.json");
            Market.GetPackageList();
        }

        Component.PackageMarket Market = new Component.PackageMarket();
        public ObservableCollection<Component.Package> Packages { get; set; } = new ObservableCollection<Component.Package>();

        public event PropertyChangedEventHandler PropertyChanged;

        public void InvokeMessage(object data, string Filter)
        {
            switch (Filter)
            {
                case "InstalledPackage":
                    {
                        break;
                    }
                case "PackageALL":
                    {
                        var p = data as List<Component.Package>;
                        foreach (var i in p)
                        {
                            Packages.Add(i);
                        }
                        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("sources"));
                        System.Diagnostics.Debug.WriteLine("当前更新了属性");
                        break;
                    }
            }
        }
    }
}
